package com.mallcai.bigdata.ladon.dpl.vo;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
public enum PeekRuleType {

    EQUALS("equals", "等于"),
    EQUALS_IGNORE_CASE("equalsIgnoreCase", "等于(不分别大小写)"),
    NOT_EQUALS("notEquals", "不等于"),
    GT("gt", "大于"),
    GTE("gte", "大于等于"),
    LT("lt", "小于"),
    LTE("lte", "小于等于"),
    CONTAINS("contains", "模糊匹配"),
    INCLUDES("includes", "包含"),
    NOT_INCLUDES("notIncludes", "不包含"),
    START_WITH("startWith", "以字符开始"),
    END_WITH("endWith", "以字符结束"),
    //
    ;

    private String code;
    private String desc;

    PeekRuleType(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static PeekRuleType getByCode(String code) {
        for (PeekRuleType prt : PeekRuleType.values()) {
            if (StringUtils.equalsIgnoreCase(prt.getCode(), code)) {
                return prt;
            }
        }
        return null;
    }

    public static String getDesc(String code) {
        for (PeekRuleType prt : PeekRuleType.values()) {
            if (StringUtils.equalsIgnoreCase(prt.getCode(), code)) {
                return prt.getDesc();
            }
        }
        return code;
    }

    /**
     * 判断是否为数字规则
     *
     * @param prt PeekRuleType
     * @return boolean
     */
    public static boolean isNumRule(PeekRuleType prt) {
        return (prt != null && (
                prt == EQUALS ||
                        prt == NOT_EQUALS ||
                        prt == GT ||
                        prt == GTE ||
                        prt == LT ||
                        prt == LTE ||
                        prt == INCLUDES ||
                        prt == NOT_INCLUDES
        ));
    }

    /**
     * 判断是否为字符串规则
     *
     * @param prt PeekRuleType
     * @return boolean
     */
    public static boolean isStringRule(PeekRuleType prt) {
        return (prt != null && (
                prt == EQUALS ||
                        prt == EQUALS_IGNORE_CASE ||
                        prt == NOT_EQUALS ||
                        prt == START_WITH ||
                        prt == END_WITH ||
                        prt == INCLUDES ||
                        prt == NOT_INCLUDES  ||
                        prt == CONTAINS
        ));
    }
}
